<template>
  <div>
    <van-form @submit="onSubmit">
      <van-notice-bar
        wrapable
        :scrollable="false"
        text="请先通过机构代码查询报考科目并填入。"
      />
      <van-field
        v-model="registerForm.org_code"
        name="registerForm.org_code"
        center
        :disabled="orgDisabled"
        clearable
        label="机构代码"
        placeholder="请输入机构代码"
        :rules="[{ required: true, message: '请输入机构代码' }]"
      >
        <template #button>
          <van-button
            native-type="button"
            size="small"
            type="info"
            :disabled="registerForm.org_code != '' ? false : true"
            @click="getOrg"
            >查找</van-button
          >
        </template>
      </van-field>
      <div v-if="userMessageIsShow">
        <van-field
          v-if="courseList.length > 0"
          :value="course_name"
          is-link
          readonly
          :rules="[{ required: true, message: '请选择报考科目' }]"
          label="报考科目"
          placeholder="请选择报考科目"
          @click="courseListIsShow = true"
        />
        <!-- <van-field
                    v-if="course_name != ''"
                    v-model="registerForm.exam_city"
                    is-link
                    readonly
                    label="考点城市"
                    placeholder="请选择考点城市"
                    @click="examCityIsShow = true"
                    :rules="[{ required:true, message: '请选择考点城市' }]"
            /> -->
        <van-popup v-model="examCityIsShow" round position="bottom">
          <van-picker
            show-toolbar
            value-key="exam_city"
            @confirm="onConfirmExamCity"
            @cancel="onCancelExamCity"
            :columns="exam_cityOptions"
          />
        </van-popup>
        <van-popup
          v-model="courseListIsShow"
          style="width: 100%; height: 40%"
          round
          position="bottom"
        >
          <van-picker
            show-toolbar
            value-key="name"
            @confirm="onConfirmCourseList"
            @cancel="onCancelCourseList"
            :columns="courseList"
          />
        </van-popup>
        <van-field
          v-model="registerForm.name"
          name="name"
          label="姓名"
          placeholder="姓名"
          :disabled="true"
          :rules="[{ required: true, message: '请填写姓名' }]"
        />
        <van-field
          v-model="registerForm.last_py"
          name="last_py"
          oninput="this.value=this.value.toUpperCase()"
          label="姓拼音"
          placeholder="姓拼音"
          :rules="[{ required: true, message: '请输入姓拼音' }]"
        />
        <van-field
          v-model="registerForm.first_py"
          name="first_py"
          oninput="this.value=this.value.toUpperCase()"
          label="名拼音"
          placeholder="名拼音"
          :rules="[{ required: true, message: '请输入名拼音' }]"
        />
        <van-cell>
          <div style="display: flex">
            <span style="width: 6.2em; margin-right: 12px; color: #969799"
              >性别</span
            >
            <van-radio-group
              :disabled="true"
              v-model="registerForm.gender"
              direction="horizontal"
            >
              <van-radio name="m">男</van-radio>
              <van-radio name="f">女</van-radio>
            </van-radio-group>
          </div>
        </van-cell>
        <van-field
          :value="cardType"
          is-link
          readonly
          label="证件类型"
          :disabled="true"
          placeholder="请选择证件类型"
          @click="cardTypeIsShow = true"
        />
        <van-popup v-model="cardTypeIsShow" round position="bottom">
          <van-picker
            show-toolbar
            value-key="name"
            @confirm="onConfirmCardType"
            @cancel="onCancelCardType"
            :columns="cardOptions"
          />
        </van-popup>
        <van-field
          v-model="registerForm.card_id"
          label="证件号码"
          placeholder="证件号码"
          :disabled="true"
          :rules="[
            {
              required: true,
              pattern:
                registerForm.card_type == 1 ? cardIdRule : /^[A-Z,a-z,\d]+$/,
              message: '格式错误',
            },
          ]"
        />
        <van-field
          readonly
          clickable
          :value="registerForm.birthday"
          label="出生日期"
          :disabled="true"
          placeholder="点击选择出生日期"
          @click="birthdayIsShow = true"
          :rules="[{ required: true, message: '请选择出生日期' }]"
        />
        <van-popup v-model="birthdayIsShow" round position="bottom">
          <van-datetime-picker
            :disabled="isNotFirstRegister"
            v-model="date.currentDate"
            type="date"
            title="选择年月日"
            :min-date="date.minDate"
            :max-date="date.maxDate"
            @confirm="onConfirmBirthday"
            @cancel="onCancelBirthday"
          />
        </van-popup>
        <van-field
          readonly
          clickable
          :value="
            jobArea
          "
          label="工作区域"
          placeholder="点击选择工作区域"
          @click="earaIsShow = true"
          :rules="[{ required: true, message: '请选择工作区域' }]"
        />
        <van-popup v-model="earaIsShow" round position="bottom">
          <van-area
            title="工作区域"
            :area-list="areaList"
            :columns-num="3"
            value="110101"
            @confirm="onConfirmArea"
            @cancel="onCancelArea"
          />
        </van-popup>
        <!-- <van-field
                    v-model="registerForm.address"
                    rows="1"
                    autosize
                    label="居住地"
                    type="textarea"
                    maxlength="30"
                    placeholder="请输入居住地"
                    show-word-limit
                    :rules="[{ required: true, message: '请填写居住地' }]"
            /> -->
        <van-field
          v-model="registerForm.hig_edu"
          is-link
          readonly
          :rules="[{ required: true, message: '请选择最高学历' }]"
          label="最高学历"
          placeholder="请选择最高学历"
          @click="higEduIsShow = true"
        />
        <van-popup v-model="higEduIsShow" round position="bottom">
          <van-picker
            show-toolbar
            value-key="name"
            @confirm="onConfirmHigEduUpdate"
            @cancel="higEduIsShow = false"
            :columns="higEduOptions"
          />
        </van-popup>

        <van-field
          readonly
          clickable
          :value="registerForm.grad_time"
          label="毕业时间"
          placeholder="点击选择毕业时间"
          @click="gradTimeIsShow = true"
          :rules="[{ required: true, message: '请选择毕业时间' }]"
        />
        <van-popup v-model="gradTimeIsShow" round position="bottom">
          <van-datetime-picker
            v-model="date.currentDate"
            type="date"
            title="选择年月日"
            :min-date="date.minDate"
            :max-date="date.maxDate"
            @confirm="onConfirmGradTimeUpdate"
            @cancel="gradTimeIsShow = false"
          />
        </van-popup>
        <van-field
          v-model="registerForm.work_age"
          type="number"
          label="从业年限"
          placeholder="请输入从业年限"
          show-word-limit
          :rules="[{ required: true, message: '请输入从业年限' }]"
        />
        <van-field
          :value="certDispaly"
          is-link
          readonly
          label="资质证书"
          :rules="[{ required: true, message: '请选择资质证书' }]"
          placeholder="请选择证书"
          @click="certDisplayIsShow = true"
        />
        <van-popup v-model="certDisplayIsShow" round position="bottom">
          <van-picker
            show-toolbar
            value-key="name"
            @confirm="onConfirmCertDispaly"
            @cancel="certDisplayIsShow = false"
            :columns="certDidpalyOptions"
          />
        </van-popup>
        <van-field
          v-model="registerForm.com_name"
          label="单位名称"
          placeholder="没有工作填写 “无” "
          :rules="[{ required: true, message: '请填写单位名称' }]"
        />
        <van-field
          :value="work_dutyName"
          is-link
          readonly
          label="现有职务"
          :rules="[{ required: true, message: '请选择现有职务' }]"
          placeholder="请选择现有职务"
          @click="work_dutyIsShow = true"
        />
        <van-popup v-model="work_dutyIsShow" round position="bottom">
          <van-picker
            show-toolbar
            value-key="name"
            @confirm="onConfirmWorkDuty"
            @cancel="work_dutyIsShow = false"
            :columns="workDutyOptions"
          />
        </van-popup>
        <van-field
          :value="indTypeName"
          is-link
          readonly
          label="行业类型"
          :rules="[{ required: true, message: '请选择行业类型' }]"
          placeholder="请选择行业类型"
          @click="ind_typeIsShow = true"
        />
        <van-popup v-model="ind_typeIsShow" round position="bottom">
          <van-picker
            show-toolbar
            value-key="name"
            @confirm="onConfirmIndType"
            @cancel="ind_typeIsShow = false"
            :columns="indTypeOptions"
          />
        </van-popup>
        <van-field
          :value="comTypeName"
          is-link
          readonly
          label="单位类型"
          :rules="[{ required: true, message: '请选择单位类型' }]"
          placeholder="请选择单位类型"
          @click="com_typeIsShow = true"
        />
        <van-popup v-model="com_typeIsShow" round position="bottom">
          <van-picker
            show-toolbar
            value-key="name"
            @confirm="onConfirmComType"
            @cancel="com_typeIsShow = false"
            :columns="comTypeOptions"
          />
        </van-popup>
        <!-- <van-cell>
                <div style="display: flex">
                    <span style="width:6.2em;margin-right: 12px">是否购书</span>
                    <van-radio-group v-model="registerForm.buy_book" direction="horizontal">
                        <van-radio :name="false">否</van-radio>
                        <van-radio :name="true">是</van-radio>
                    </van-radio-group>
                </div>
            </van-cell> -->
        <van-field
          label="电子邮箱"
          v-model="registerForm.email"
          placeholder="电子邮箱"
          :rules="[{ pattern: emailRule, message: '请输入正确内容' }]"
        />
        <van-field
          label="手机号码"
          v-model="registerForm.phone"
          placeholder="请输入手机号码"
          :rules="[{ pattern: phoneRule, message: '手机号码格式错误' }]"
        />
        <van-field
          v-model="registerForm.code"
          name="code"
          center
          clearable
          placeholder="请输入短信验证码"
          :rules="[{ pattern: codeRule, message: '短信验证码长度为四位' }]"
        >
          <template #button>
            <tencent-captcha
              :phone="registerForm.phone"
              :phoneRule="phoneRule"
              scene="1"
            ></tencent-captcha>
          </template>
        </van-field>
        <van-cell>
          <van-checkbox v-model="registerForm.agree" shape="square"
            >本人已阅读并同意<a href="#" @click.prevent="isPrivacyFun">《隐私政策》</a
            ><a href="#" @click="isRegisterFun">《用户注册协议》</a>
          </van-checkbox>
        </van-cell>
        <!--            <van-dialog v-model="signIsShow" title="电子签名" @close="registerClose" @confirm="registerSubmit" show-cancel-button>-->
        <!--                <div style="width: 100%;display: flex;justify-content: center">-->
        <!--                    <vue-esign ref="esign" :width="300" :height="150" style="border: 1px solid gray"/>-->
        <!--                </div>-->
        <!--            </van-dialog>-->
        <van-overlay :show="signIsShow" @click="signIsShow = false">
          <div
            style="
              width: 100%;
              height: 100%;
              display: flex;
              justify-content: center;
              align-items: center;
            "
          >
            <div
              style="padding: 20px; border-radius: 5px; background-color: wheat"
            >
              <vue-esign
                ref="esign"
                :width="300"
                :height="150"
                style="border: 1px solid gray; background: white"
              />
              <div
                style="
                  width: 100%;
                  margin-top: 20px;
                  display: flex;
                  justify-content: space-around;
                "
              >
                <van-button @click.prevent="registerClose">取消</van-button>
                <van-button @click="registerReset">重置</van-button>
                <van-button @click.prevent="registerSubmit">提交</van-button>
              </div>
            </div>
          </div>
        </van-overlay>
        <!--            <div style="width: 100%;height:100%;display: flex;justify-content: center;align-items: center">-->
        <!--                <div style="padding: 20px;border-radius: 5px;background-color: wheat">-->
        <!--                    <vue-esign ref="esign" :width="300" :height="150" style="border: 1px solid gray;background: white"/>-->
        <!--                    <div style="width: 100%;margin-top:20px;display: flex;justify-content: space-around">-->
        <!--                        <van-button @click="registerReset">重置</van-button>-->
        <!--                    </div>-->
        <!--                </div>-->
        <!--            </div>-->
        <div style="margin: 16px">
          <van-button round block type="info" native-type="submit"
            >提交</van-button
          >
        </div>
      </div>
    </van-form>
  </div>
</template>

<script>
import Pinyin from "js-pinyin";
import { changeName } from "../../../../utils/changName";
import TencentCaptcha from "../../../../components/TencentCaptcha/TencentCaptcha";
import { getOrg } from "../../../../request/api";
import { Dialog, Notify } from "vant";
import { formatDate } from "../../util/date";
import { areaList } from "@vant/area-data";
export default {
  name: "registerForm",
  props: {
    userMessage: {
      type: Object,
      default: null,
    },
    registerParams: {
      type: Array,
      default: [],
    },
    isNotFirstRegister: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      work_dutyIsShow: false,
      ind_typeIsShow: false,
      com_typeIsShow: false,
      comTypeOptions: [
        { name: "事业单位", value: 1 },
        { name: "人力资源服务机构", value: 2 },
        { name: "会计（税务,律师）事务所", value: 3 },
        { name: "其他中介机构", value: 4 },
        { name: "金融机构（银行,证券,保险,信托,基金等）", value: 5 },
        { name: "院校", value: 6 },
        { name: "其他", value: 7 },
      ],
      indTypeOptions: [
        { name: "集成电路", value: 1 },
        { name: "人工智能", value: 2 },
        { name: "软件与平台", value: 3 },
        { name: "生命与科学", value: 4 },
        { name: "生物医药", value: 5 },
        { name: "医疗保健", value: 6 },
        { name: "航空宇航天", value: 7 },
        { name: "汽车", value: 8 },
        { name: "化工", value: 9 },
        { name: "工业产品和服务", value: 10 },
        { name: "消费品", value: 11 },
        { name: "能源和自然资源", value: 12 },
        { name: "金融", value: 13 },
        { name: "基础建设和建筑产品", value: 14 },
        { name: "机械和设备", value: 15 },
        { name: "媒体", value: 16 },
        { name: "金属和矿业", value: 17 },
        { name: "私募基金", value: 18 },
        { name: "零售", value: 19 },
        { name: "高科技", value: 20 },
        { name: "电信", value: 21 },
        { name: "公用事业", value: 22 },
        { name: "教育", value: 23 },
        { name: "文化", value: 24 },
        { name: "人力资源与人力资本服务", value: 25 },
        { name: "其他", value: 26 },
        { name: "无", value: 27 },
      ],
      workDutyOptions: [
        {
          name: "事务所负责人/高级管理人员（董事长/权益合伙人/授薪合伙人等）",
          value:
            "事务所负责人/高级管理人员（董事长/权益合伙人/授薪合伙人等）Head of the firm / Senior Management (Chairman / Equity Partners / Salaried Partners, etc.)",
        },
        {
          name: "单位负责人/高级管理人员（董事长/总裁/副总裁等）",
          value:
            "单位负责人/高级管理人员（董事长/总裁/副总裁等）Person in charge / Senior Management (Chairman / President / Vice President, etc.)",
        },
        {
          name: "人力资源部（薪酬专员岗/薪税服务专员岗）",
          value:
            "人力资源部（薪酬专员岗/薪税服务专员岗）Human Resources Dept. (Payments Specialist Post/Payments and Tax Service Specialist Post)",
        },
        {
          name: "人力资源部（薪酬总监岗及以上/薪税服务总监岗及以上）",
          value:
            "人力资源部（薪酬经理岗/薪税服务经理岗）Human Resources Dept. (Payments Manager Post/Payments and Tax Service Manager Post)",
        },
        {
          name: "人力资源部（薪酬总监岗及以上/薪税服务总监岗及以上）",
          value:
            "人力资源部（薪酬总监岗及以上/薪税服务总监岗及以上）Human Resources Dept. (Payments Director Post and above/Payments and Tax Service Director Post and above)",
        },
        {
          name: "财务部（专员岗）",
          value: "财务部（专员岗）Finance Dept. (Specialist Post)",
        },
        {
          name: "财务部（经理岗）",
          value: "财务部（经理岗）Finance Dept. (Manager Post)",
        },
        {
          name: "财务部（总监岗及以上）",
          value:
            "财务部（总监岗及以上）Finance Dept. (Director Post and above)",
        },
        {
          name: "其他未列明部门（专员岗）",
          value:
            "其他未列明部门（专员岗）Other Unspecified Departments (Specialist Post)",
        },
        {
          name: "其他未列明部门（经理岗）",
          value:
            "其他未列明部门（经理岗）Other Unspecified Departments (Manager Post)",
        },
        {
          name: "其他未列明部门（总监岗及以上）",
          value:
            "其他未列明部门（总监岗及以上）Other Unspecified Departments (Director Post and above)",
        },
        {
          name: "客服部/市场部/业务部（专员岗）",
          value:
            "客服部/市场部/业务部（专员岗）Customer Service Dept. / Marketing Dept. / Business Dept. (Specialist Post)",
        },
        {
          name: "客服部/市场部/业务部（经理岗）",
          value:
            "客服部/市场部/业务部（经理岗）Customer Service Dept. / Marketing Dept. / Business Dept. (Manager Post)",
        },
        {
          name: "客服部/市场部/业务部（总监岗及以上）",
          value:
            "客服部/市场部/业务部（总监岗及以上）Customer Service Dept. / Marketing Dept. / Business Dept. (Director Post and above)",
        },
        {
          name: "业务部（专员岗）",
          value: "业务部（专员岗）Business Dept. (Specialist Post)",
        },
        {
          name: "业务部（经理岗）",
          value: "业务部（经理岗）Business Dept. (Manager Post)",
        },
        {
          name: "业务部（总监岗及以上）",
          value:
            "业务部（总监岗及以上）Business Dept. (Director Post and above)",
        },
      ],
      orgDisabled: false,
      course: null,
      flag: false,
      sex: { 1: "m", 2: "f" },
      certType: { 0: "1", 1: "2", B: "3", C: "4" },
      userMessageIsShow: false,
      emailRule: /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/,
      phoneRule:
        /^[1](([3][0-9])|([4][0,1,4-9])|([5][0-3,5-9])|([6][2,5,6,7])|([7][0-8])|([8][0-9])|([9][0-3,5-9]))[0-9]{8}$/,
      codeRule: /\d{4}/,
      date: {
        minDate: new Date(1970, 0, 1),
        maxDate: new Date(),
        currentDate: new Date(),
      }, //年月日对象
      cardIdRule:
        /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/,
      courseListIsShow: false,
      cardTypeIsShow: false,
      birthdayIsShow: false,
      examCityIsShow: false,
      earaIsShow: false,
      signIsShow: false,
      higEduIsShow: false,
      gradTimeIsShow: false,
      certDisplayIsShow: false,
      date: {
        minDate: new Date(1970, 0, 1),
        maxDate: new Date(),
        currentDate: new Date(),
      }, //年月日对象
      higEduOptions: ["博士及以上", "研究生", "本科", "专科", "其他"],
      loading: true,
      cardOptions: [
        { id: 1, name: "居民身份证" },
        { id: 2, name: "护照" },
        { id: 3, name: "港澳居民通行证" },
        { id: 4, name: "台湾居民通行证" },
      ],
      certDidpalyOptions: [
        { id: 0, name: "没有任何证书" },
        { id: 1, name: "人力资源管理师一级" },
        { id: 2, name: "人力资源管理师二级" },
        { id: 3, name: "人力资源管理师三级" },
        { id: 4, name: "人力资源管理师四级" },
        { id: 5, name: "税务师" },
        { id: 6, name: "注册会计师" },
        { id: 7, name: "会计师高级" },
        { id: 8, name: "会计师中级" },
        { id: 9, name: "会计师初级" },
        { id: 10, name: "经济师高级" },
        { id: 11, name: "经济师中级" },
        { id: 12, name: "经济师初级" },
        { id: 13, name: "律师" },
        { id: 14, name: "ACCA" },
        { id: 15, name: "AICPA" },
        { id: 16, name: "IFA" },
        { id: 17, name: "ATHE国际薪税师二级（中级）" },
        { id: 18, name: "ATHE国际薪税师三级（初级）" },
        { id: 19, name: "CMA", 20: "CIMA" },
      ],
      //预计考点城市
      exam_cityOptions: [],
      registerForm: {
        cert: 0, //资质证书
        org_code: "", //机构
        course_id: "", //科目
        name: "", //学员姓名 --潘童
        last_py: "", //姓拼音
        first_py: "", //名拼音
        gender: "m", //性别
        card_type: 1, //证件类型
        birthday: "", //出生日期
        card_id: "", //证件号码 --320723199807023528
        phone: "", //手机号码 --18360556606
        email: "", //电子邮箱 --181501830@qq.com
        code: "",
        hig_edu: "", //最高学历
        grad_time: "", //毕业时间
        work_age: 0, //工作年限
        province: "", //省份 --江苏省
        city: "", //城市 --南京市
        address: "", //居住地
        exam_city: "", //预计考点城市
        com_name: "", //单位名称 --爱柔则有限公司
        work_duty: "", //现有职务 --总经理助理
        buy_book: false, //是否购书
        sign: "", //电子签名
        agree: false, //是否同意培训合同
        ind_type: "", //行业类型
        com_type: "", //单位类型
        dis: "", //区/县
      },
      courseList: [], //科目集合
      areaList: areaList,
    };
  },
  methods: {
    isRegisterFun() {
      window.open("/train_register.html");
    },
    isPrivacyFun() {
      window.open("/train_privacy.html");
    },
    //条件判断
    flagFunction() {
      if (
        this.course.filter((item) => item.id == this.registerForm.course_id)[0]
          .name == "国际薪税师高级"
      ) {
        console.log("进入");
        switch (this.registerForm.hig_edu) {
          case "博士及以上":
            this.flag = true;
            break;
          case "研究生":
            this.flag =
              this.DateDiffer(this.registerForm.grad_time) > 1 ? true : false;
            console.log("修改后Flag", this.flag);
            break;
          case "本科":
            this.flag =
              this.DateDiffer(this.registerForm.grad_time) > 3 ? true : false;
            console.log(this.flag);
            break;
          case "专科":
            this.flag =
              this.DateDiffer(this.registerForm.grad_time) > 4 ? true : false;
            break;
        }
        if (this.registerForm.work_age >= 6) {
          this.flag = true;
        }
        for (let item of this.certDidpalyOptions) {
          switch (item.id) {
            case 0:
              this.$set(item, "flag", "没有任何证书");
              break;
            case 1:
            case 5:
            case 6:
            case 7:
            case 10:
            case 13:
            case 14:
            case 15:
            case 16:
              this.$set(item, "flag", 0);
              break;
            case 2:
            case 8:
            case 11:
            case 17:
            case 19:
            case 20:
              this.$set(item, "flag", 1);
              break;
            case 3:
            case 4:
            case 9:
            case 12:
            case 18:
              this.$set(item, "flag", 3);
          }
        }
        for (let item of this.certDidpalyOptions) {
          if (item.id == this.registerForm.cert) {
            if (this.registerForm.work_age >= item.flag) {
              this.flag = true;
            }
          }
        }
        console.log("flag", this.flag);
      } else if (
        this.course.filter((item) => item.id == this.registerForm.course_id)[0]
          .name == "国际薪税师中级"
      ) {
        switch (this.registerForm.hig_edu) {
          case "博士及以上":
            this.flag = true;
            break;
          case "研究生":
            this.flag = true;
            break;
          case "本科":
            this.flag =
              this.DateDiffer(this.registerForm.grad_time) > 2 ? true : false;
            break;
          case "专科":
            this.flag =
              this.DateDiffer(this.registerForm.grad_time) > 3 ? true : false;
            break;
        }
        if (this.registerForm.work_age >= 2) {
          this.flag = true;
        }
        for (let item of this.certDidpalyOptions) {
          switch (item.id) {
            case 0:
              this.$set(item, "flag", "没有任何证书");
              break;
            case 1:
            case 2:
            case 5:
            case 6:
            case 7:
            case 8:
            case 10:
            case 11:
            case 13:
            case 14:
            case 15:
            case 16:
            case 17:
            case 19:
            case 20:
              this.$set(item, "flag", 0);
              break;
            case 3:
            case 4:
            case 9:
            case 12:
            case 18:
              this.$set(item, "flag", 1);
              break;
          }
        }
        for (let item of this.certDidpalyOptions) {
          if (item.id == this.registerForm.cert) {
            if (this.registerForm.work_age >= item.flag) {
              this.flag = true;
            }
          }
        }
        console.log("flag", this.flag);
      } else if (
        this.course.filter((item) => item.id == this.registerForm.course_id)[0]
          .name == "国际薪税师初级"
      ) {
        this.flag = true;
      }
    },
    //创建方法er
    DateDiffer(Date_end) {
      //date1结束时间
      let date1 = new Date(Date_end);
      //date2当前时间
      let date2 = new Date();
      date1 = new Date(date1.getFullYear(), date1.getMonth(), date1.getDate());
      date2 = new Date(date2.getFullYear(), date2.getMonth(), date2.getDate());
      const diff = date2.getTime() - date1.getTime(); //当前时间减去毕业时间
      const diffDate = diff / (24 * 60 * 60 * 1000 * 365); //计算当前时间与结束时间之间相差天数
      console.log("毕业天数", diffDate);
      return diffDate;
    },
    onConfirmGradTimeUpdate(value) {
      let value2 = formatDate(value, "yyyy-MM-dd");
      console.log(`毕业时间当前值${value2}`);
      this.registerForm.grad_time = value2;
      this.gradTimeIsShow = false;
    },
    onConfirmHigEduUpdate(value) {
      console.log("最高学历", value);
      this.registerForm.hig_edu = value;
      this.higEduIsShow = false;
    },
    onConfirmExamCity(value) {
      console.log("考点城市", value);
      this.registerForm.exam_city = value.exam_city;
      this.examCityIsShow = false;
    },
    onCancelExamCity() {
      this.examCityIsShow = false;
    },
    onSubmit() {
      if (this.registerForm.agree === false) {
        Notify({
          type: "warning",
          message:
            "请勾选是否已阅读《培训合同内容》并确认《个人信息安全保护条款》",
        });
      } else if (this.registerForm.course_id === "") {
        Notify({
          type: "warning",
          message: "请通过机构代码查询科目内容并填入",
        });
      } else {
        // this.signIsShow = true;
        this.flagFunction();
        if (this.flag == true) {
          this.registerSubmit();
        } else {
          Notify({ type: "warning", message: "对不起,您暂不满足报考条件" });
        }
      }
    },
    getOrg() {
      getOrg(this.registerForm.org_code).then((res) => {
        this.course = res.course;
        Dialog.confirm({
          title: "机构名称",
          message: `所查找的机构是否是${res.org_name}`,
        })
          .then(() => {
            this.courseList = res.course;
            this.userMessageIsShow = true;
            this.orgDisabled = true;
          })
          .catch(() => {
            // on cancel
          });
      });
    },
    onConfirmCourseList(value, index) {
      console.log(`当前值${value.id}`);
      this.registerForm.course_id = value.id;
      this.courseListIsShow = false;
    },
    onCancelCourseList() {
      this.courseListIsShow = false;
    },
    onConfirmCardType(value, index) {
      console.log(`当前值${value.id}`);
      this.registerForm.card_type = value.id;
      this.cardTypeIsShow = false;
    },
    onConfirmCertDispaly(value, index) {
      console.log(`当前值${value.id}`);
      this.registerForm.cert = value.id;
      this.certDisplayIsShow = false;
    },
    onConfirmWorkDuty(value, index) {
      this.registerForm.work_duty = value.value;
      this.work_dutyIsShow = false;
    },
    onConfirmIndType(value, index) {
      this.registerForm.ind_type = value.value;
      this.ind_typeIsShow = false;
    },
    onConfirmComType(value, index) {
      this.registerForm.com_type = value.value;
      this.com_typeIsShow = false;
    },

    onCancelCardType() {
      this.cardTypeIsShow = false;
    },
    onConfirmBirthday(value) {
      let value2 = formatDate(value, "yyyy-MM-dd");
      console.log(`当前值${value2}`);
      this.registerForm.birthday = value2;
      this.birthdayIsShow = false;
    },
    onCancelBirthday() {
      this.birthdayIsShow = false;
    },
    onConfirmArea(value) {
      this.registerForm.province = value[0].name;
      this.registerForm.city = value[1].name;
      this.registerForm.dis = value[2].name;
      this.earaIsShow = false;
      console.log(value);
    },
    onCancelArea() {
      this.earaIsShow = false;
    },
    registerSubmit() {
      // this.$refs.esign.generate().then(res => {
      //     this.registerForm.sign = res;
      //     console.log('报名表单',this.registerForm);
      //     this.$emit('handleRegister',this.registerForm);
      //     this.signIsShow = false;
      // }).catch(error =>{
      //     // Notify({ type: 'warning', message: '请填写电子签名' });
      // })
      // this.registerForm.sign = res;
      console.log("报名表单", this.registerForm);
      this.$emit("handleRegister", this.registerForm);
    },
    registerClose() {
      console.log("取消");
      this.signIsShow = false;
    },
    registerReset() {
      this.$refs.esign.reset();
    },
  },
  created() {
    console.log(this.registerParams);
    console.log("本地用户信息", this.userMessage);
    if (this.userMessage != null) {
      this.registerForm.name = this.userMessage.person.personName;
      console.log("证件类型", this.certType[this.userMessage.person.certType]);
      this.registerForm.card_type =
        this.certType[this.userMessage.person.certType];
      this.registerForm.card_id = this.userMessage.person.idCard;
      console.log("性别", this.sex[this.userMessage.person.sex]);
      this.registerForm.gender = this.sex[this.userMessage.person.sex];
      this.registerForm.phone = this.userMessage.person.mobile;
      // this.registerForm.address = this.userMessage.person.address;
      // let reg = /.+?(省|市|自治区|自治州|县|区)/g
      // console.log('省份',this.registerForm.address.match(reg));
      // let areaArray = this.registerForm.address.match(reg);
      // this.registerForm.province = areaArray[0];
      // this.registerForm.city = areaArray[1];
      // this.registerForm.dis = areaArray[2];
      // let {lastname,firstname} = changeName(this.registerForm.name);
      // console.log('changeName',lastname,firstname);
      // console.log(Pinyin.getFullChars(lastname));
      // this.registerForm.last_py = Pinyin.getFullChars(lastname);
      // this.registerForm.first_py = Pinyin.getFullChars(firstname);

      this.registerForm.birthday =
        this.registerForm.card_id.substring(6, 14).slice(0, 4) +
        "-" +
        this.registerForm.card_id.substring(6, 14).slice(4, 6) +
        "-" +
        this.registerForm.card_id.substring(6, 14).slice(6);
    }
    if (this.registerParams.length > 0) {
      for (let item in this.registerForm) {
        // console.log(this.registerForm[item],this.registerParams[this.registerParams.length - 1][item]);
        // this.registerParams[this.registerParams.length - 1]['exam_city'] = '';
        this.registerForm[item] =
          this.registerParams[this.registerParams.length - 1][item];
      }
    }
  },
  computed: {
    jobArea(){
      let province = this.registerForm.province == null ? '' :this.registerForm.province;
      let city = this.registerForm.city == null ? '' :this.registerForm.city;
      let dis = this.registerForm.dis == null ? '' :this.registerForm.dis;
      console.log(province)
      return province + '/' +city + '/' + dis
    },
    course_name() {
      if (this.registerForm.course_id !== "") {
        let course_name = "";
        for (let item of this.courseList) {
          if (item.id == this.registerForm.course_id) {
            console.log(item);
            console.log("item.examdate", item.examdate);
            this.exam_cityOptions = item.examdate;
            course_name = item.name;
          }
        }
        return course_name;
      }
      return "";
    },
    cardType() {
      let cardTypeName = "";
      for (let item of this.cardOptions) {
        if (item.id == this.registerForm.card_type) {
          console.log(item);
          // this.exam_cityOptions = item.examdate
          cardTypeName = item.name;
        }
      }
      return cardTypeName;
    },
    indTypeName() {
      let indTypeName = "";
      for (let item of this.indTypeOptions) {
        if (item.value == this.registerForm.ind_type) {
          console.log(item);
          // this.exam_cityOptions = item.examdate
          indTypeName = item.name;
        }
      }
      return indTypeName;
    },
    work_dutyName() {
      let work_dutyName = "";
      for (let item of this.workDutyOptions) {
        if (item.value == this.registerForm.work_duty) {
          console.log(item);
          // this.exam_cityOptions = item.examdate
          work_dutyName = item.name;
        }
      }
      return work_dutyName;
    },
    comTypeName() {
      let comTypeName = "";
      for (let item of this.comTypeOptions) {
        if (item.value == this.registerForm.com_type) {
          console.log(item);
          // this.exam_cityOptions = item.examdate
          comTypeName = item.name;
        }
      }
      return comTypeName;
    },
    certDispaly() {
      let certDisplayName = "";
      for (let item of this.certDidpalyOptions) {
        if (item.id == this.registerForm.cert) {
          console.log(item);
          // this.exam_cityOptions = item.examdate
          certDisplayName = item.name;
        }
      }
      return certDisplayName;
    },
  },
  components: {
    TencentCaptcha,
  },
};
</script>

<style scoped>
canvas {
  background-color: white !important;
}
</style>
